Skip to content

fix(inversion): regularization_weights_mapper_dict uses correct linear_obj_list index - #304

Merged
Jammy2211 merged 1 commit into
mainfrom
feature/regularization-weights-mapper-index-fix
May 10, 2026
Merged

Jammy2211 merged 1 commit into
mainfrom
feature/regularization-weights-mapper-index-fix

Conversation

@Jammy2211

Copy link
Copy Markdown
Collaborator

Summary

Fixes AbstractInversion.regularization_weights_mapper_dict mis-indexing when a non-Mapper linear object precedes a source Mapper in linear_obj_list. The mapper's dict slot was being populated with the regularization weights of whichever linear_obj_list[i] happened to share its enumerated position in the Mapper-only sublist — for a typical MGE-lens-light + pixelized-source layout, that meant the 40-element lens MGE weights ended up keyed under a 530-pixel source mapper. matplotlib's ax.tripcolor then refused to render the source-plane regularization-weights subplot in inversion_0_0.png, logging Could not plot the source-plane via the Mapper: The length of c must match either the number of points or the number of triangles. The numerical reconstruction itself was unaffected.

API Changes

None — internal indexing fix in AbstractInversion.regularization_weights_mapper_dict. The property's signature and return type are unchanged; the dict now correctly maps each Mapper to its own regularization weights when other linear objects sit ahead of it in linear_obj_list. See full details below.

Test Plan

  • python -m pytest test_autoarray/inversion/inversion/test_abstract.py -k regularization_weights_mapper_dict -v — two new regression tests pass.
  • python -m pytest test_autoarray/inversion/ — full inversion suite (164 tests) green.
  • End-to-end verified: re-running an Euclid vis_pix Nautilus fit no longer emits Could not plot the source-plane via the Mapper log lines.
Full API Changes (for automation & release notes)

Removed

  • None.

Added

  • None.

Renamed

  • None.

Changed Signature

  • None.

Changed Behaviour

  • autoarray.inversion.inversion.abstract.AbstractInversion.regularization_weights_mapper_dict — when linear_obj_list contains non-Mapper entries (e.g. LightProfileLinearObjFuncList) ahead of a Mapper, the dict slot for that mapper now contains the mapper's own regularization weights rather than the weights of whichever linear obj happened to share its Mapper-only enumerate index. Inversions whose linear_obj_list starts with a Mapper produced correct output before and after this change.

Migration

  • None required. Public API is unchanged.

🤖 Generated with Claude Code

…r_obj_list index

`regularization_weights_mapper_dict` iterated `enumerate(cls_list_from(cls=Mapper))` and passed the resulting Mapper-only index into `regularization_weights_from`, which looks up `self.linear_obj_list[index]`. When a non-Mapper linear object (e.g. a `LightProfileLinearObjFuncList` for an MGE bulge) precedes the source mapper in `linear_obj_list`, the dict ended up keyed with the wrong linear obj's regularization weights — e.g. the 40-element lens MGE weights stored under a 530-pixel source mapper. matplotlib's `ax.tripcolor` then refused to render the source-plane regularization-weights subplot with "The length of c must match either the number of points or the number of triangles".

Replace the enumerate-based index with `self.linear_obj_list.index(mapper)` so each mapper receives weights derived from its own entry. New regression tests verify the dict slot for a Mapper preceded by a linear obj (and for two mappers separated by a linear obj) holds that mapper's weights.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@Jammy2211 Jammy2211 added the pending-release PR queued for the next release build label May 10, 2026
@Jammy2211
Jammy2211 merged commit 46bb880 into main May 10, 2026
4 checks passed
@Jammy2211
Jammy2211 deleted the feature/regularization-weights-mapper-index-fix branch May 10, 2026 11:14
@Jammy2211 Jammy2211 removed the pending-release PR queued for the next release build label Sep 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant